package com.otojob.config;

import com.otojob.utils.interceptor.LoginInterceor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;
import org.springframework.web.servlet.config.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;

/**
 * @Description
 * @Author: TingFeng
 * @CreateTime: 2022/4/11  21:24
 */

@Configuration
public class WebConfiguration implements WebMvcConfigurer {

    @Autowired
    private LoginInterceor tokenInterceptor;

//    /**
//     * 解决跨域请求
//     * @param registry
//     */
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                .allowedHeaders("*")
//                .allowedMethods("*")
//                .allowedOriginPatterns("*")
//                .allowCredentials(true);
//    }
//
//    /**
//     * 异步请求配置
//     * @param configurer
//     */
//    @Override
//    public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
//        configurer.setTaskExecutor(new ConcurrentTaskExecutor());
//        configurer.setDefaultTimeout(30000);
//    }

    /**
     * 配置拦截器、拦截路径
     * 每次请求到拦截的路径，就会去执行拦截器中的方法
     * @param
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> excludePath = new ArrayList<>();
//        excludePath.add("/register");
        excludePath.add("/swagger-ui.html/**");
        excludePath.add("/home/**");
        excludePath.add("/wx/**");
        excludePath.add("/jobList/**");
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")//所有路径都被拦截 ，可以配置那些路径拦截 使用多个registration.addPathPatterns("");
                .excludePathPatterns(excludePath)
        .excludePathPatterns("/api/**",
                "/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");//那些路径不拦截
        WebMvcConfigurer.super.addInterceptors(registry);
    }

}

